﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace Services
{
    /// <summary>
    /// Service1 的摘要说明
    /// </summary>

    public partial class TestServices : WebService
    {
        [WebMethod]
        [SoapHeader("accessToken", Direction = SoapHeaderDirection.InOut, Required = true)]
        public bool Login(string name, string pwd)
        {
            if (AppContext.LoginUsers.Contains(name))
            {
                Context.Session["CurrentUser"] = name;
                return true;
            }
            if (AppContext.Users.Keys.Contains(name) && AppContext.Users[name] == pwd)
            {
                AppContext.LoginUsers.Add(name);
                Context.Session["CurrentUser"] = name;
                return true;
            }
            return false;
        }

        [WebMethod]
        [SoapHeader("accessToken", Direction = SoapHeaderDirection.InOut, Required = true)]
        public void LogOut()
        {
            string name = Session["CurrentUser"]?.ToString();
            if (!string.IsNullOrEmpty(name) && AppContext.LoginUsers.Contains(name))
            {
                AppContext.LoginUsers.Remove(name);
            }
            Session["CurrentUser"] = null;
        }
    }
}
